/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.pg.misra.rules;

import java.util.ArrayList;
import java.util.List;
import pl.pg.misra.AST.AST;
import pl.pg.misra.Interfaces.IRule;

/**
 *
 * @author Paweł
 */
public class DoNotMixUnaryOperatorsWithBinaryOperatorsRule extends AbstractRule implements IRule{

    @Override
    public List<String> checkRule(List<AST> asts) {
        List<String> result = new ArrayList<>();
        List<String> binaryParameters = new ArrayList<>();
        List<String> unaryParameters = new ArrayList<>();
        
        binaryParameters.add("*");
        binaryParameters.add("+");
        binaryParameters.add("-");
        binaryParameters.add("/");
        binaryParameters.add("=");
        
        unaryParameters.add("++");
        unaryParameters.add("--");
        
        for (AST functionNode : asts){
            List<AST> searchResult = new ArrayList<>();
            
            searchResult = findNodesByTypeAndParameters("BinaryOperator", functionNode, searchResult, binaryParameters);
            
            for (AST operatorNode : searchResult){
                List<AST> unaryOperators = new ArrayList<>();
                
                unaryOperators = findNodesByTypeAndParameters("UnaryOperator", operatorNode, unaryOperators, unaryParameters);
                
                if (unaryOperators.size() > 0){
                    result.add(buildViolationMessage(functionNode, "12.13", "increment or decrement statemets should not be mixed with other arithmetic operations"));
                }
            }
        }
        
        return result;
    }
    
}
